package com.kly.cashmall.utils.data;

import android.content.Context;
import android.content.res.Resources;

/**
 * @author
 */
public class DensityUtil {

  /**
   * 将px值转换为dip或dp值，保证尺寸大小不变
   **/
  @Deprecated public static int px2dip(Context context, float pxValue) {
    return px2dip(pxValue);
  }

  public static int px2dip(float pxValue) {
    final float scale = Resources.getSystem().getDisplayMetrics().density;
    return (int) (pxValue / scale + 0.5f);
  }

  /**
   * 将dip或dp值转换为px值，保证尺寸大小不变
   **/
  @Deprecated public static int dip2px(Context context, float dipValue) {
    return dip2px(dipValue);
  }

  public static int dip2px(float dipValue) {
    final float scale = Resources.getSystem().getDisplayMetrics().density;
    return (int) (dipValue * scale + 0.5f);
  }

  /**
   * 将px值转换为sp值，保证文字大小不变
   **/
  @Deprecated public static int px2sp(Context context, float pxValue) {
    return px2sp(pxValue);
  }

  public static int px2sp(float pxValue) {
    final float scale = Resources.getSystem().getDisplayMetrics().scaledDensity;
    return (int) (pxValue / scale + 0.5f);
  }

  /**
   * 将sp值转换为px值，保证文字大小不变
   **/
  @Deprecated public static int sp2px(Context context, float spValue) {
    return sp2px(spValue);
  }

  public static int sp2px(float spValue) {
    final float fontScale = Resources.getSystem().getDisplayMetrics().scaledDensity;
    return (int) (spValue * fontScale + 0.5f);
  }

  /**
   * 获取屏幕宽度width
   */
  public static int getScreenWidth() {
    return Resources.getSystem().getDisplayMetrics().widthPixels;
  }

  /**
   * 获取屏幕宽度width
   */
  public static int getScreenHeight() {
    return Resources.getSystem().getDisplayMetrics().heightPixels;
  }
}